package com.zhu.day.learn;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

public class Solution {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(0, head);
        ListNode first = head;
        ListNode second = dummy;
        for (int i = 0; i < n; ++i) {
            first = first.next;
        }
        while (first != null) {
            first = first.next;
            second = second.next;
        }
        second.next = second.next.next;
        ListNode ans = dummy.next;
        return ans;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        ListNode s = new ListNode();
    }
    @NoArgsConstructor
    @AllArgsConstructor
    static
    class ListNode{
        int val;
        ListNode next;
    }

}
